<?php
include("global_files/global_pgsql.inc");
$db=new cDatabase();
$login_name=$_POST["login_name"];

$db->search_path="payir_schema";
$db->setSearchPath();
$login_name=trim($_POST["login_name"]);
$password=trim($_POST["access_code"]);
$db->query="select farmer_id from login_details where login_name='$login_name' and password='$password';";
$db->runQuery();
$authentication_details=$db->returnArrays();
$farmer_id=$authentication_details[0]["farmer_id"];

// if authentication fails then throw an error message
if(!$farmer_id)
	{
	$msg="Login failed, Please try again! or Register";
	unset($_SESSION);
	session_destroy();
	header("Location:register.php?msg=$msg");
	exit;
	}

$db=new cDatabase();
$db->query="select farmer_name from farmer where farmer_id=$farmer_id;";
$db->runQuery();
$name_array=$db->returnArrays();

session_start();

$_SESSION["gfarmer_id"]=$farmer_id;
$_SESSION["gfarmer_name"]=$name_array[0]["farmer_name"];

header("Location:./payir-entry.php");
?>
